﻿
SET QUOTED_IDENTIFIER ON
GO

SET ANSI_NULLS ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE [object_id] = OBJECT_ID(N'[dbo].[fn_GetTimeValue]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
    DROP FUNCTION [dbo].[fn_GetTimeValue];
GO
CREATE FUNCTION [dbo].[fn_GetTimeValue]
(
    @DateTime datetime,
    @IncludeSeconds bit = 0
)
returns int
with schemabinding
as
begin

if @IncludeSeconds = 0
	return datepart(hour, @DateTime)*10000 + datepart(minute, @DateTime)*100;

return datepart(hour, @DateTime)*10000 + datepart(minute, @DateTime)*100 + datepart(second, @DateTime);

end
GO